package cntv.player.core;

import android.content.Context;
import android.os.Environment;

public class CBoxFileUtil {
	private static final String APP_FILE_Directory = "cntv.cn";
/*	private static final String XML_REMOTE_URL = "http://dispatch.3g.cntv.cn/approve/getchannel_area_shadow_all";
	private static final String NOW_PLAY_JSON_URL = "http://epg.app.cntv.cn/approve/livep";
	private static final String EPG_JSON_URL = "http://epg.app.cntv.cn/approve/epginfo";
	private static final String IMAGE_REMOTE_URL = "http://t.live.cntv.cn/newp2pb/images/ico/";
	private static final String XML_FILE_NAME = "channel.xml";
	private static final int XML = 0;
	private static final int IMAGE = 1;
	private static final int TRY_NUMBER = 5;*/
	
	/**
	 * 获取data/data目录
	 * @return
	 */
	public static String getDataPath(){
		return Environment.getDataDirectory().getAbsolutePath() + "/data/";
	}

	
    /**
     * 判断是否存在sd卡
     * @return
     */
    public static boolean hasSDCard() {
		String status = Environment.getExternalStorageState();
		if (!status.equals(Environment.MEDIA_MOUNTED)) {
			return false;
		} 
		return true;
	}
	
    /**
     * 获取文件根目录
     * @return
	 *  	<ul>
	 *     	<li> /sdcard/ if sdcard exist
	 *     	<li> /data/data/  if sdcard not exist
	 *     </ul>
     */
	public static String getRootFilePath() {
		if (hasSDCard()) {
			return Environment.getExternalStorageDirectory().getAbsolutePath() + "/";// filePath:/sdcard/
		} else {
			return Environment.getDataDirectory().getAbsolutePath() + "/data/"; // filePath: /data/data/
		}
	}
	
    /**
     * 获取文件根目录
     * @return
	 *  	<ul>
	 *     	<li> /sdcard/Android/data/data/{packageName}/file/     if sdcard exist
	 *     	<li> /data/data/   if sdcard not exist
	 *     </ul>
     */
	public static String getRootFilePath(Context context) { 
		if (hasSDCard()&&context.getExternalFilesDir(null)!=null) {
			return context.getExternalFilesDir(null).getAbsolutePath() + "/";// filePath:/sdcard/Android/data/data/{packageName}/file/
		} else {
			return Environment.getDataDirectory().getAbsolutePath() + "/data/"; // filePath: /data/data/
		}
	}
	
	/**
	 * 获取文件目录
	 * @return
	 *  	<ul>
	 *     	<li> /sdcard/cntv.cn   if sdcard exist
	 *     	<li> /data/data/cntv.cn   if sdcard not exist
	 *     </ul>
	 */
	public static String getAppFilePath() {
			return getRootFilePath() + APP_FILE_Directory;
	}
	
	/**
	 * 获取文件目录
	 * @return
	 *  	<ul>
	 *     	<li> /sdcard/Android/data/data/{packageName}/file/cntv.cn       if sdcard exist
	 *     	<li> /data/data/cntv.cn   if sdcard not exist
	 *     </ul>
	 */
	public static String getAppFilePath(Context context) {
			return getRootFilePath(context)+APP_FILE_Directory;
	}
	
}
